package com.api.shopapi.mapper;

import com.api.shopapi.entity.AskAnswerRecordSite;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface AskAnswerRecordSiteMapper {


    @Insert("insert into ask_answer_record_site " +
            "(" +
            "AskAnswerRecordSiteCode," +
            "AskAnswerRecordCode," +
            "Sort,"+
            "CreateTime"+
            ") " +
            "values " +
            "(" +
            "#{askAnswerRecordSite.AskAnswerRecordSiteCode}," +
            "#{askAnswerRecordSite.AskAnswerRecordCode}," +
            "#{askAnswerRecordSite.Sort}," +
            "#{askAnswerRecordSite.CreateTime}" +
            ")" )
    int insert(@Param("askAnswerRecordSite") AskAnswerRecordSite askAnswerRecordSite);


    @Delete("delete from ask_answer_record_site where askAnswerRecordSiteCode=#{askAnswerRecordSiteCode}")
    int delete(@Param("askAnswerRecordSiteCode") String askAnswerRecordSiteCode);

    @Select("select * from ask_answer_record_site where askAnswerRecordSiteCode=#{askAnswerRecordSiteCode} limit 1")
    AskAnswerRecordSite getByAskAnswerRecordSiteCode(@Param("askAnswerRecordSiteCode") String askAnswerRecordSiteCode);

    @Select("select * from ask_answer_record_site where askAnswerRecordCode=#{askAnswerRecordCode}" +
            " and sort=#[sort} limit 1")
    AskAnswerRecordSite getByAskAnswerRecordCodeSort(@Param("askAnswerRecordCode") String askAnswerRecordCode,
                                                     @Param("sort") int sort);


    @Select("select * from ask_answer_record_site where askAnswerRecordCode=#{askAnswerRecordCode} order by sort desc")
    List<AskAnswerRecordSite> listByAskAnswerRecordCode(@Param("askAnswerRecordCode") String askAnswerRecordCode);



}
